<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.model.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" rev="stylesheet" href="../css/style.css" type="text/css" media="all" />
<script type="text/javascript" src="../js/jquery-1.9.1.min.js" ></script>
<script language="JavaScript" type="text/javascript">
function slt_chg() {
	var slt = $("#slt").val();
	
	if( slt === "其他库房" ) {
		$("#store").prop( "value", "" );
		$("#room").prop( "value", "" );
		$("#store").prop( "readonly", false );
		$("#room").prop( "readonly", false );
	}
	else if ( slt === "直接出库" ) {
		$("#store").prop( "value", "" );
		$("#room").prop( "value", "" );
		$("#store").prop( "readonly", true );
		$("#room").prop( "readonly", true );
	}
	else {
		$("#store").prop( "readonly", true );
		$("#room").prop( "readonly", true );
		$("#store").prop( "value", slt );
		
		var url = "StoreInfo";
		var method = "POST";
		
		$.ajax({
			url: url,
			type: method,
			data: {
				slt: slt,
			},
			dataType: "json",
			success: function( data ) {
				$("#room").prop( "value", data.room );
			}
		});
	}
}

function slt_chk() {
	if( $("#amount").val() === "直接出库" ){
		return true;
	}
	else if( $("#amount").val() === "" ) {
		alert("请输入数量");
		return false;
	}
	else if( ($("#slt").val() === "其他库房") && ( ($("#store").val() === "") || ($("#room").val() === "") ) ) {
		alert("库房信息不全");
		return false;
	}
	else if( $("#person").val() === "" ) {
		alert("请选择经手人");
		return false;
	}
	else {
		var url = "ItemAmountCheck";
		var method = "POST";
		var ack = false;
		var iid = $("#iid").val();
		var amount = $("#amount").val();
		$.ajax({
			url: url,
			type: method,
			async:false,
			data: {
				iid: iid,
				amount: amount
			},
			dataType: "json",
			success: function( data ) {
				ack = data.ack;
			}
		});
		if( ack )
			return true;
		else {
			$("#amount").prop("value", "数量太多了！");
			return false;
		}
	}
}

</script>
<style type="text/css">
<!--
.atten {font-size:12px;font-weight:normal;color:#F00;}
-->
</style>
</head>

<body class="ContentBody">
<%
	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");

	Connection con = DataBase.getConnection();

	//TODO: rewrite the sql clause
	PreparedStatement pstmtInfo = con.prepareStatement("SELECT * FROM item where iid=?");
	String iid = request.getParameter("iid");
	pstmtInfo.setString(1, iid);
  	ResultSet rsInfo = pstmtInfo.executeQuery();
  	if( !rsInfo.next() )
  	{%>
	无效物品！请勿做非法输入！
	<%}
  	else{  		
%>
<form action="ItemDeal?flag=out" method="post" name="form" id="form" onsubmit="return slt_chk()" >
<input type="hidden" name="iid" id="iid" value="<%=iid %>" />
<div class="MainDiv">
<table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
  <tr>
      <th class="tablestyle_title" >物品信息修改</th>
  </tr>
  <tr>
    <td class="CPanel">
		
		<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
		<tr><td align="left">
		<input type="button" name="Submit" value="保存" class="button" onclick="alert('保存成功！');"/>　
			
			<input type="button" name="Submit2" value="返回" class="button" onclick="window.history.go(-1);"/>
		</td></tr>
		<TR>
			<TD width="100%">
				<fieldset style="height:100%;">
				<legend>物品信息</legend>
					  <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
					 
					  <tr>
					    <td nowrap="nowrap" align="right" width="15%">物品名称:</td>
					    <td width="35%"><input name="name" id="name" class="text" style="width:154px" value="<%=rsInfo.getString("name") %>" readonly /></td>
						<td nowrap="nowrap" align="right">物品品牌:</td>
					    <td><input class="text" name="brand" id="brand" style="width:154px" value="<%=rsInfo.getString("brand") %>" readonly="readonly" /></td>
					  </tr>

					  <tr>
					  	<td width="16%" align="right" nowrap="nowrap">数量:</td>
					    <td width="34%"><input class="text" name="amount" id="amount" style="width:154px" value="" onclick="$('#amount').prop('value', '')" /></td>
					    <td nowrap="nowrap" align="right">计量单位:</td>
					    <td><input class="text" name="unit" id="unit" style="width:154px" value="<%=rsInfo.getString("unit") %>" readonly="readonly" /></td>
					  </tr>
                      
                      <tr>
						<td nowrap="nowrap" align="right">出库位置:</td>
					    <td>
					    	<select name="slt" id="slt" class="text" style="width:154px" onchange="slt_chg()">
					    		<option>直接出库</option>
					    	<%
					  			PreparedStatement pstmtStrLst = con.prepareStatement("SELECT name FROM store_room");
					  			ResultSet rsStrLst = pstmtStrLst.executeQuery();
					  			while( rsStrLst.next() ) {%>
					    			<option value="<%=rsStrLst.getString("name") %>"><%=rsStrLst.getString("name") %></option>
					    		<%}
					  			rsStrLst.close();
					  			%>
					    		<option>其他库房</option>
					    	</select>
					    </td>
					    <td align="right">经手人:</td>
					    <td><input class="text" name="person" id="person" style="width:154px" value="<%=rsInfo.getString("person") %>"/></td>
					  </tr>
					  
					  <tr>					  
						<td align="right">部门名称:</td>
					  	<td><input class="text" name="store" id="store" style="width:154px" readonly="readonly" /></td>
					  	<td align="right">房间位置:</td>
					  	<td><input class="text" name="room" id="room" style="width:154px" readonly="readonly" /></td>
					  </tr>
					 
					  <tr>
					    <td align="right">备注:</td>
					    <td colspan="3"><textarea name="description" id="description" cols="100" rows="8"></textarea></td>
					  </tr>
					  </table>
			  <br />
				</fieldset>			</TD>
			
		</TR>
		

		
		
		
		</TABLE>
	
	
	 </td>
  </tr>
  
  
		
		
		
		<TR>
			<TD colspan="2" align="center" height="50px">
			<input type="submit" name="Submit" value="保存" class="button" />　
			
			<input type="button" name="Submit2" value="返回" class="button" onclick="window.history.go(-1);"/></TD>
		</TR>
		</TABLE>
	
	
	 </td>
  </tr>
  
  
  
  </table>

</div>
</form>
<%}
	rsInfo.close();
	con.close();
%>
</body>
</html>
